﻿using Castle.ActiveRecord;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Online_Course.Domain
{
    [ActiveRecord]
    public class SystemFunction : BaseEntity<SystemFunction>
    {

        [Property(Length = 99, NotNull = false)]
        [Display(Name = "菜单名")]
        public string Name { get; set; }

        [Property(Length = 99, NotNull = false)]
        [Display(Name = "控制器名称")]
        public string ConName { get; set; }

        [Property(Length = 99, NotNull = false)]
        [Display(Name = "类名")]
        public string ClazzName { get; set; }

        [Property(Length = 99, NotNull = false)]
        [Display(Name = "Action名称")]
        public string ActionName { get; set; }

        /// <summary>
        /// 排序码
        /// </summary>
        [Display(Name = "排序码")]
        [Property(NotNull = true, Default = "10")]
        [Required(ErrorMessage = "不能为空")]
        public int SortCode { get; set; }

        /// <summary>
        /// 是否在菜单中显示
        /// </summary>
        [Display(Name = "是否显示")]
        [Property(NotNull = false)]
        public bool IsShow
        { get; set; }

        /// <summary>
        /// 上级模块
        /// </summary>
        [BelongsTo(Type = typeof(SystemFunction), Column = "ParentId", Lazy = FetchWhen.OnInvoke)]
        [Display(Name = "上级模块")]
        public SystemFunction ParentSysMenu { get; set; }

        /// <summary>
        /// 有权限的角色
        /// </summary>
        [HasAndBelongsToMany(typeof(SysRole), Table = "SysRole_SystemFunction", ColumnRef = "SysRoleId", ColumnKey = "SystemFunctionId", Cascade = ManyRelationCascadeEnum.None, Lazy = false)]
        [Display(Name = "菜单属于角色")]
        public IList<SysRole> SysRoleList { get; set; }
    }
}
